package com.sunxboy.platform.option;

import org.springframework.util.Assert;

public enum Options {
    LOGLEVEL {
        public String toString() {
            return "--core:logLevel";
        }

        @Override
        protected void processValue(CommandLineOptions comLineOptions, String value) {
            comLineOptions.setLogLevel(value);
        }
    },

    HOME {
        public String toString() {
            return "--core:home";
        }

        @Override
        protected void processValue(CommandLineOptions comLineOptions, String value) {
            comLineOptions.setSharedHome(value);
        }

    },

    ENV {
        public String toString() {
            return "--core:env";
        }

        @Override
        protected void processValue(CommandLineOptions comLineOptions, String value) {

            comLineOptions.setEnvironment(value);
        }

    },

    APPID {
        public String toString() {
            return "--core:appId";
        }

        @Override
        protected void processValue(CommandLineOptions comLineOptions, String value) {
            comLineOptions.setApplicationId(value);
        }

    },

    INSTANCEID {
        public String toString() {
            return "--core:instanceId";
        }

        @Override
        protected void processValue(CommandLineOptions comLineOptions, String value) {
            comLineOptions.setInstanceId(value);
        }

    },

    LOGCONFIG {
        public String toString() {
            return "--core:logConfig";
        }

        @Override
        protected void processValue(CommandLineOptions comLineOptions, String value) {
            comLineOptions.setLogConfigLocation(value);
        }

    };

    public static Options toOption(String str) {
        try {
            String option = str.replace("--core:", "");
            Assert.notNull(option, "Required option is missing");
            return Options.valueOf(option.trim().toUpperCase());
        }
        catch (Exception e) {
            return null;
        }
    }

    abstract protected void processValue(CommandLineOptions comLineOptions, String value);
}
